import React from 'react';
import './App.css';
import 'semantic-ui-css/semantic.min.css'
import { BrowserRouter,Route,Redirect,Switch } from "react-router-dom"
import Login from'./Login.js';
import AuthCheck from './authCheck.js' 
import Main from './Moudel/Main.js'

import axios from 'axios';

// 基本路径
axios.defaults.baseURL = 'http://47.96.21.88:8086/'

// 请求拦截器
axios.interceptors.request.use(function(config){
    if(!config.url.endsWith('/login')){
        config.headers.Authorization = sessionStorage.getItem('mytoken',)
    }
    return config
})

// 响应拦截器
axios.interceptors.response.use(function(res){
    // 返回res.data使获得数据时可以少写一层data
    return res.data
})

// function Home(){
//     return <div>主页</div>
// }

// function authCheck(){
//     let token = sessionStorage.getItem('myget')
//     if(!token){
//         return <Redirect to="/login"></Redirect>
//     }
//     return <div>test</div>
// }

function Hello(){
    return <div>你好</div>
}

function Test(){
    return <div>测试</div>
}

function App(){
    return(
        <BrowserRouter>
            <Switch>
                <Route path='/login' component={ Login }></Route>
                <Route path='/home' component={ Main }></Route>
                {/* <AuthCheck path='/home' component={ Home }></AuthCheck> */}
                {/* <Route path='/test' render={authCheck}></Route> */}
                <AuthCheck path='/hello' component={Hello}></AuthCheck>
                <AuthCheck path='/test' component={Test}></AuthCheck>
                <Redirect from="/" to="/login"/>
            </Switch>
        </BrowserRouter>
    )
}

export default App;
